package org.example.memora.mapper;

import org.apache.ibatis.annotations.*;
import org.example.memora.annotation.AutoFill;
import org.example.memora.common.enumeration.OperationType;
import org.example.memora.entity.User;

import java.util.List;


@Mapper
public interface UserMapper {

    // 获取所有用户
    @Select("SELECT * FROM users")
    List<User> findAll();

    // 根据 ID 获取用户
    User findById(Long id);

    User findByUsername(String username);
    // 插入新用户（已添加新字段）
    @Insert("INSERT INTO users (username, password, email, phone, avatar_url, nickname, gender, birthday, school, region, bio) " +
            "VALUES (#{username}, #{password}, #{email}, #{phone}, #{avatarUrl}, #{nickname}, #{gender}, #{birthday}, #{school}, #{region}, #{bio})")
    @Options(useGeneratedKeys = true, keyProperty = "userId")
    void save(User user);

    // 删除用户
    @Delete("DELETE FROM users WHERE user_id = #{id}")
    void deleteById(Long id);
    @AutoFill(value= OperationType.UPDATE)
    void update(User user);
    User findByPhone(String phone);
    User findByEmail(String email);
}
